#include <iostream>
#include <map>
using namespace std;

const int N=1e5+10;
int n,m,L,V;
int t;
int a[N],d[N],v[N],p[N];

int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--)
    {
        int ans=0;
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++)
            cin>>d[i]>>v[i]>>a[i];
        for(int i=1;i<=m;i++)
            cin>>p[i];
        for(int i=1;i<=n;i++)
        {
            if(d[i]<=p[m]&&v[i]>V)
                ans++;
        }
        cout<<ans<<" "<<m-1<<endl;
    }
    return 0;
}
